package c2.cross.business.guildwar;

import c2.advanced.business.base.AdvancedDaoTemplate;
import c2.cross.share.DbFacade4Cross;
import cate.game.pvp.guildwar.data.rank.GWGuildRank;
import cate.game.pvp.guildwar.data.rank.GWRoleRank;
import com.mongodb.client.result.DeleteResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.mongodb.core.query.Query;

import java.util.Collection;
import java.util.List;

@Slf4j
public class GuildWarDao extends AdvancedDaoTemplate {

    public GuildWarDao(DbFacade4Cross root) {
        super(root);
    }

    //拉取玩家功勋排行榜
    public List<GWRoleRank> getRoleList() {
        long beginTime = System.currentTimeMillis();
        List<GWRoleRank> list = this.mongo().findAll(GWRoleRank.class, GWRoleRank.COLLECTION);
        log.info("公会战-玩家排行榜拉取结束 ,耗时{}ms 共有{}个玩家 ", (System.currentTimeMillis() - beginTime),list.size());
        return list;
    }

    //更新玩家功勋排行榜
    public Collection<GWRoleRank> updateRankList(List<GWRoleRank> list) {
        DeleteResult dr = this.mongo().remove(new Query(), GWRoleRank.COLLECTION);
        log.info("公会战-玩家排行榜更新list前先删除数据{}条, wasAcknowledged={}", dr.getDeletedCount(), dr.wasAcknowledged());
        Collection<GWRoleRank> r = this.mongo().insert(list, GWRoleRank.COLLECTION);
        log.info("公会战-玩家排行榜试图insert {} 个数据, 实际插入 {} 个数据", list.size(), r.size());
        return r;
    }

    //拉取公会积分排行榜
    public List<GWGuildRank> getGuildList() {
        long beginTime = System.currentTimeMillis();
        List<GWGuildRank> list = this.mongo().findAll(GWGuildRank.class, GWGuildRank.COLLECTION);
        log.info("公会战-公会排行榜拉取结束 ,耗时{}ms 共有{}个公会", (System.currentTimeMillis() - beginTime), list.size());
        return list;
    }

    //更新公会积分排行榜
    public Collection<GWGuildRank> updateGuildList(List<GWGuildRank> list) {
        DeleteResult dr = this.mongo().remove(new Query(), GWGuildRank.COLLECTION);
        log.info("公会战-公会排行榜更新list前先删除数据{}条, wasAcknowledged={}", dr.getDeletedCount(), dr.wasAcknowledged());
        Collection<GWGuildRank> r = this.mongo().insert(list, GWGuildRank.COLLECTION);
        log.info("公会战-公会排行榜试图insert {} 个数据, 实际插入 {} 个数据", list.size(), r.size());
        return r;
    }


}
